<template>
  <div>
    <table-ext :columns="columns" :searchForm="searchForm" :config="config" ref="tableExt">
      <template slot="table-action">
        <el-button type="primary" icon="el-icon-plus" @click="addInspect">新增</el-button>
      </template>
    </table-ext>
    <!-- 废弃修改弹框 -->
    <!-- <el-dialog title="作废" :visible.sync="dialogFormVisible">
      <el-form :model="addOrUpdateForm" ref="addOrUpdateForm" label-width="100px">
        <el-form-item label="废弃原因:" prop="abolishReason" style="margin-bottom: 22px">
          <el-input v-model="addOrUpdateForm.abolishReason"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('addOrUpdateForm'); dialogFormVisible = false">取 消</el-button>
        <el-button @click="resetForm('addOrUpdateForm')" v-if="!dialogUpdate">重置</el-button>
        <el-button type="primary" @click="abolish(addOrUpdateForm)">确 定</el-button>
      </div>
    </el-dialog> -->
    <!-- <el-dialog title="删除" :visible.sync="dialogFormVisibler" class="ppx">
      <el-form :model="addOrUpdateForm1" ref="addOrUpdateForm" label-width="100px">
        <span>是否执行该操作？</span>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibler = false">取 消</el-button>
        <el-button type="primary" @click="abolishere(addOrUpdateForm1)">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>
<script>
  import SelectTree from '@/components/common/select-ext/select-tree.vue';
  import TableExt from '@/components/common/table-ext/table-ext.vue';
  import TableIcon from '@/components/common/table-ext/table-icon';
  export default {
    // 引入自定义表格组件
    components: {
      SelectTree,
      'table-ext': TableExt,
      TableIcon
    },
    data() {
      return {
        // 弹框属性
        isShow: false,
        formInline: {},
        purOrgOptions: [],
        relationPurGroup: [],
        addOrUpdateForm: {
          abolishReason: '',
          id: ''
        },
        addOrUpdateForm1: {},
        // 弹框显示控制
        // dialogFormVisible: false,
        dialogFormVisibler: false,
        // 修改弹框控制
        dialogUpdate: false,
        config: { // 页面共通配置
          title: '工厂考察评估', //页面标题
          isPage: true, //是否分页
          isNo: false, //是否显示序号
          align:'center',//表格居中
          selection: false, //是否显示复选框
          crudMapping: { // CRUD方法
            query: {
              url: this.lib.config.host.vendorDlv + "/vendormgt/dlv/factoryInspect/factoryInspectMgt/query",
              method: 'post'
            }
          }
        },
        searchForm: [{ // 查询表单配置
            label: '采购组织',
            key: 'purOrgId',
            type: 'select',
            dict: {
              url: this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/' + this.getCurrUserId(),
              method: 'get',
              label: 'purOrgName',
              value: 'id'
            }
          }, {
            label: '采购组',
            key: 'purGroupId',
            type: 'select',
            dict: {
              url: this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/{purOrgId}',
              method: 'post',
              label: 'purGroupName',
              value: 'id'
            }
          }, {
            label: '单据号',
            key: 'inspectNo',
            type: 'input'
          },
          {
            label: '标题',
            key: 'title',
            type: 'input'
          }, {
            label: '申请人',
            key: 'publishUserName',
            type: 'input'
          },
          {
            label: '品类',
            key: 'categoryCode',
            type: 'select-tree'
          }, {
            label: '评估类型',
            key: 'inspectType',
            type: 'select',
            dict: [{
              value: '1',
              label: '初审'
            }, {
              value: '2',
              label: '年度复审'
            }]
          }, {
            label: '发布状态',
            key: 'publishStatus',
            type: 'select',
            dict: [{
              value: '0',
              label: '未发布'
            }, {
              value: '1',
              label: '已发布'
            }]
          }, {
            label: '审核状态',
            key: 'checkStatus',
            type: 'select',
            dict: [{
                value: '0',
                label: '未审核'
              }, {
                value: '1',
                label: '已审核'
              },
              {
                value: '-1',
                label: '驳回'
              }, {
                value: '3',
                label: '待审核'
              }
            ]
          }, {
            label: '完成状态',
            key: 'completeStatus',
            type: 'select',
            dict: [{
              value: '0',
              label: '未完成'
            }, {
              value: '1',
              label: '已完成'
            }, {
              value: '2',
              label: '部分完成'
            }, ]
          }, {
            label: '废弃状态',
            key: 'abolishStatus',
            type: 'select',
            dict: [{
              value: '0',
              label: '未作废'
            }, {
              value: '1',
              label: '已作废'
            }]
          }
        ],
        // 表格列定义
        columns: [{
          width: '100px',
          label: '操作', // 表格header
          render: (createElement, params) => { // 动态渲染，click事件示例
            let _this = this;
            // if (params.row.abolishStatus === this.lib.common.status.YES) { //取params 没有this
            //   return createElement('div', {}, [createElement('el-button', {
            //     props: {
            //       type: 'text',
            //     }
            //   }, '--')]);
            // }
            //  else if (params.row.checkStatus === this.lib.common.status.YES && params.row.completeStatus ===
            //   this.lib.common.status.NO) {
            //   return createElement('div', {}, [createElement('el-button', {
            //     props: {
            //       type: 'text',
            //     },
            //     on: {
            //       click() {
            //         _this.addOrUpdateForm = Object.assign({}, {
            //           id: params.row.id
            //         });
            //         _this.dialogUpdate = true;
            //         _this.dialogFormVisible = true;
            //       }
            //     }
            //   }, '废弃')])
            // };
            if (params.row.publishStatus === this.lib.common.status.YES || params.row.abolishStatus === this.lib.common
              .status.YES) {
              return createElement('div', '--');
            } else {
              return createElement('div', {}, [createElement('el-button', {
                  props: {
                    type: 'text',
                  },
                  on: {
                    click() {
                      _this.$router.push({
                        path: '/Index/VendorDlv/Editor',
                        query: {
                          id: params.row.id,
                        }
                      });
                    }
                  }
                }, '编辑'),
                createElement('el-button', {
                  props: {
                    type: 'text',
                  },
                  on: {
                    click() {
                      _this.abolishere(params.row.id)
                      // _this.addOrUpdateForm1 = Object.assign({}, _this.addOrUpdateForm1, {
                      //   id: params.row.id
                      // });
                      // _this.dialogFormVisibler = true;
                    }
                  }
                }, '删除')
              ], )
            }

          }
        }, {
          label: '采购组织',
          key: 'purOrgName',
          width: '180'
        }, {
          label: '采购组',
          key: 'purGroupName',
          width: '180'
        }, {
          label: '单据号',
          key: 'inspectNo',
          width: '180',
          render: (createElement, params) => { // 动态渲染，click事件示例
            let _this = this;
            return createElement('div', {}, [createElement('a', {
              style: {
                color: '#409EFF',
                cursor: 'pointer'
              },
              on: {
                click() {
                  _this.setCurrent(params.row);
                }
              }
            }, params.row.inspectNo)]);
          }
        }, {
          label: '标题',
          key: 'title',
          width: '200px'
        }, {
          label: '评估类型',
          key: 'inspectType',
          render: (createElement, params) => { //动态渲染, 字典表示例
            let inspectType = params.row.inspectType;
            if (inspectType == 1) {
              return createElement('div', '初审');
            } else {
              return createElement('div', '年度复审');
            }
          }
        }, {
          label: '品类',
          key: 'categoryName',
          width: '200px'
        }, {
          label: '申请人',
          key: 'publishUserName',
          width: '120'
        }, {
          label: '发布时间',
          key: 'publishTime',
          width: '100'
        }, {
          label: '发布状态',
          key: 'publishStatus',
          render: (createElement, params) => { //动态渲染, 字典表示例
            return createElement(TableIcon, {
              props: {
                flag: params.row.publishStatus,
                titles: [{
                  status: 0,
                  title: '未发布'
                }, {
                  status: 1,
                  title: '已发布'
                }]
              }
            });
          }
        }, {
          label: '审核状态',
          key: 'checkStatus',
          render: (createElement, params) => { //动态渲染, 字典表示例
            return createElement(TableIcon, {
              props: {
                flag: params.row.checkStatus,
                titles: [{
                  status: 0,
                  title: '未审核'
                }, {
                  status: 1,
                  title: '已审核'
                }, {
                  status: -1,
                  title: '驳回'
                }]
              }
            });
          }
        }, {
          label: '评估岗位',
          key: 'sysStationName',
          width: '120'
        }, {
          label: '完成状态',
          key: 'completeStatus',
          render: (createElement, params) => { //动态渲染, 字典表示例
            return createElement(TableIcon, {
              props: {
                flag: params.row.completeStatus,
                titles: [{
                  status: 0,
                  title: '未完成'
                }, {
                  status: 1,
                  title: '已完成'
                }]
              }
            });
          }
        }, {
          label: '废弃状态',
          key: 'abolishStatus',
          render: (createElement, params) => { //动态渲染, 字典表示例
            return createElement(TableIcon, {
              props: {
                flag: params.row.abolishStatus,
                titles: [{
                  status: 0,
                  title: '未废弃'
                }, {
                  status: 1,
                  title: '已废弃'
                }]
              }
            });
          }
        }, {
          label: '废弃原因',
          key: 'abolishReason',
          width: '160px'
        }]

      };
    },
     created(){
      if(this.$route.query){
        this.config.crudMapping.query.data=this.$route.query
      }
    },
    methods: {
      addInspect() {
        this.$router.push('/Index/VendorDlv/VendorInspectAdd');
      },
      //废除
      // abolish(addOrUpdateForm) {
      //   this.axios.post(this.lib.config.host.vendorDlv + '/vendormgt/dlv/factoryInspect/abolish/' + addOrUpdateForm.id,
      //       addOrUpdateForm)
      //     .then((response) => {
      //       this.dialogFormVisible = false;
      //       this.$router.push('/Index/VendorDlv/VendorInspect');
      //     })
      //     .catch(function (error) {
      //       console.log(error);
      //     });
      // },
      //删除
      abolishere(id) {
        this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        this.axios.post(this.lib.config.host.vendorDlv + '/vendormgt/dlv/factoryInspect/factoryInspectMgt/' + id)
          .then((response) => {
            if (response.data.success) {
              this.dialogFormVisibler = false;
              this.$message({
                message: '删除成功！',
                type: 'success'
              });
              this.$refs['tableExt'].refreshTable();
            }
          })
          .catch(function (error) {
            console.log(error);
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });



      },
      //点击编码 跳转到新页面
      setCurrent({
        id,
        inspectNo
      }) {
        window.open(`/FactoryInspectItem?id=${id}&inspectNo=${inspectNo}`)
      }
    }
  }

</script>
